package com.chenfan.mcn.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Objects;

/**
 * @author:   tangwei
 * Date:     2021/5/10 16:22
 * Description: 开票形式
 */
@AllArgsConstructor
@SuppressWarnings("AlibabaEnumConstantsMustHaveComment")
public enum InvoiceFormEnum {

    /**
     * 开票形式
     */
    NO_NEED_INVOICE(0, "无需开票"),
    UNCERTAIN_INVOICE(1, "开票待定"),
    NEED_INVOICE(2, "开票"),
    ;

    @Getter
    private Integer type;

    @Getter
    private String desc;

    public static InvoiceFormEnum getByType(Integer type) {
        for (InvoiceFormEnum invoiceFormEnum : InvoiceFormEnum.values()) {
            if (invoiceFormEnum.getType().equals(type)) {
                return invoiceFormEnum;
            }
        }
        return null;
    }

    public static boolean needAutoInvoice(Integer type) {
        if(Objects.isNull(type)) {
            return false;
        }
        return InvoiceFormEnum.NO_NEED_INVOICE.getType().equals(type) || InvoiceFormEnum.NEED_INVOICE.getType().equals(type);
    }

    public static String getDesc(Integer type) {
        for (InvoiceFormEnum invoiceFormEnum : InvoiceFormEnum.values()) {
            if (invoiceFormEnum.getType().equals(type)) {
                return invoiceFormEnum.getDesc();
            }
        }
        return null;
    }
}